.class public Lnet/oauth/ConsumerProperties;
.super Ljava/lang/Object;
.source "ConsumerProperties.java"


# instance fields
.field private final consumerProperties:Ljava/util/Properties;

.field private final pool:Ljava/util/Map;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/Map",
            "<",
            "Ljava/lang/String;",
            "Lnet/oauth/OAuthConsumer;",
            ">;"
        }
    .end annotation
.end field


# direct methods
.method public constructor <init>(Ljava/lang/String;Ljava/lang/ClassLoader;)V
    .locals 1
    .parameter "resourceName"
    .parameter "loader"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 60
    invoke-static {p1, p2}, Lnet/oauth/ConsumerProperties;->getResource(Ljava/lang/String;Ljava/lang/ClassLoader;)Ljava/net/URL;

    move-result-object v0

    invoke-static {v0}, Lnet/oauth/ConsumerProperties;->getProperties(Ljava/net/URL;)Ljava/util/Properties;

    move-result-object v0

    invoke-direct {p0, v0}, Lnet/oauth/ConsumerProperties;-><init>(Ljava/util/Properties;)V

    .line 61
    return-void
.end method

.method public constructor <init>(Ljava/util/Properties;)V
    .locals 1
    .parameter "consumerProperties"

    .prologue
    .line 63
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 69
    new-instance v0, Ljava/util/HashMap;

    invoke-direct {v0}, Ljava/util/HashMap;-><init>()V

    iput-object v0, p0, Lnet/oauth/ConsumerProperties;->pool:Ljava/util/Map;

    .line 64
    iput-object p1, p0, Lnet/oauth/ConsumerProperties;->consumerProperties:Ljava/util/Properties;

    .line 65
    return-void
.end method

.method public static getProperties(Ljava/net/URL;)Ljava/util/Properties;
    .locals 3
    .parameter "source"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 48
    invoke-virtual {p0}, Ljava/net/URL;->openStream()Ljava/io/InputStream;

    move-result-object v0

    .line 50
    .local v0, input:Ljava/io/InputStream;
    :try_start_0
    new-instance v1, Ljava/util/Properties;

    invoke-direct {v1}, Ljava/util/Properties;-><init>()V

    .line 51
    .local v1, p:Ljava/util/Properties;
    invoke-virtual {v1, v0}, Ljava/util/Properties;->load(Ljava/io/InputStream;)V
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 54
    invoke-virtual {v0}, Ljava/io/InputStream;->close()V

    return-object v1

    .end local v1           #p:Ljava/util/Properties;
    :catchall_0
    move-exception v2

    invoke-virtual {v0}, Ljava/io/InputStream;->close()V

    throw v2
.end method

.method public static getResource(Ljava/lang/String;Ljava/lang/ClassLoader;)Ljava/net/URL;
    .locals 4
    .parameter "name"
    .parameter "loader"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 40
    invoke-virtual {p1, p0}, Ljava/lang/ClassLoader;->getResource(Ljava/lang/String;)Ljava/net/URL;

    move-result-object v0

    .line 41
    .local v0, resource:Ljava/net/URL;
    if-nez v0, :cond_0

    .line 42
    new-instance v1, Ljava/io/IOException;

    new-instance v2, Ljava/lang/StringBuilder;

    invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V

    const-string v3, "resource not found: "

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    invoke-direct {v1, v2}, Ljava/io/IOException;-><init>(Ljava/lang/String;)V

    throw v1

    .line 44
    :cond_0
    return-object v0
.end method

.method private getURL(Ljava/net/URL;Ljava/lang/String;)Ljava/lang/String;
    .locals 2
    .parameter "base"
    .parameter "name"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/net/MalformedURLException;
        }
    .end annotation

    .prologue
    .line 123
    iget-object v1, p0, Lnet/oauth/ConsumerProperties;->consumerProperties:Ljava/util/Properties;

    invoke-virtual {v1, p2}, Ljava/util/Properties;->getProperty(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v0

    .line 124
    .local v0, url:Ljava/lang/String;
    if-eqz p1, :cond_0

    .line 125
    new-instance v1, Ljava/net/URL;

    invoke-direct {v1, p1, v0}, Ljava/net/URL;-><init>(Ljava/net/URL;Ljava/lang/String;)V

    invoke-virtual {v1}, Ljava/net/URL;->toExternalForm()Ljava/lang/String;

    move-result-object v0

    .line 127
    :cond_0
    return-object v0
.end method


# virtual methods
.method public getConsumer(Ljava/lang/String;)Lnet/oauth/OAuthConsumer;
    .locals 4
    .parameter "name"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/net/MalformedURLException;
        }
    .end annotation

    .prologue
    .line 74
    iget-object v3, p0, Lnet/oauth/ConsumerProperties;->pool:Ljava/util/Map;

    monitor-enter v3

    .line 75
    :try_start_0
    iget-object v2, p0, Lnet/oauth/ConsumerProperties;->pool:Ljava/util/Map;

    invoke-interface {v2, p1}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lnet/oauth/OAuthConsumer;

    .line 76
    .local v0, consumer:Lnet/oauth/OAuthConsumer;
    monitor-exit v3
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0

    .line 77
    if-nez v0, :cond_0

    .line 78
    invoke-virtual {p0, p1}, Lnet/oauth/ConsumerProperties;->newConsumer(Ljava/lang/String;)Lnet/oauth/OAuthConsumer;

    move-result-object v0

    .line 80
    :cond_0
    iget-object v3, p0, Lnet/oauth/ConsumerProperties;->pool:Ljava/util/Map;

    monitor-enter v3

    .line 81
    :try_start_1
    iget-object v2, p0, Lnet/oauth/ConsumerProperties;->pool:Ljava/util/Map;

    invoke-interface {v2, p1}, Ljava/util/Map;->get(Ljava/lang/Object;)Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Lnet/oauth/OAuthConsumer;

    .line 82
    .local v1, first:Lnet/oauth/OAuthConsumer;
    if-nez v1, :cond_1

    .line 83
    iget-object v2, p0, Lnet/oauth/ConsumerProperties;->pool:Ljava/util/Map;

    invoke-interface {v2, p1, v0}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;

    .line 91
    :goto_0
    monitor-exit v3
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_1

    .line 92
    return-object v0

    .line 76
    .end local v0           #consumer:Lnet/oauth/OAuthConsumer;
    .end local v1           #first:Lnet/oauth/OAuthConsumer;
    :catchall_0
    move-exception v2

    :try_start_2
    monitor-exit v3
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_0

    throw v2

    .line 89
    .restart local v0       #consumer:Lnet/oauth/OAuthConsumer;
    .restart local v1       #first:Lnet/oauth/OAuthConsumer;
    :cond_1
    move-object v0, v1

    goto :goto_0

    .line 91
    .end local v1           #first:Lnet/oauth/OAuthConsumer;
    :catchall_1
    move-exception v2

    :try_start_3
    monitor-exit v3
    :try_end_3
    .catchall {:try_start_3 .. :try_end_3} :catchall_1

    throw v2
.end method

.method protected newConsumer(Ljava/lang/String;)Lnet/oauth/OAuthConsumer;
    .locals 13
    .parameter "name"
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/net/MalformedURLException;
        }
    .end annotation

    .prologue
    .line 97
    iget-object v8, p0, Lnet/oauth/ConsumerProperties;->consumerProperties:Ljava/util/Properties;

    new-instance v9, Ljava/lang/StringBuilder;

    invoke-direct {v9}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {v9, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v9

    const-string v10, ".serviceProvider.baseURL"

    invoke-virtual {v9, v10}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v9

    invoke-virtual {v9}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v9

    invoke-virtual {v8, v9}, Ljava/util/Properties;->getProperty(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v0

    .line 99
    .local v0, base:Ljava/lang/String;
    if-nez v0, :cond_2

    const/4 v1, 0x0

    .line 100
    .local v1, baseURL:Ljava/net/URL;
    :goto_0
    new-instance v7, Lnet/oauth/OAuthServiceProvider;

    new-instance v8, Ljava/lang/StringBuilder;

    invoke-direct {v8}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {v8, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v8

    const-string v9, ".serviceProvider.requestTokenURL"

    invoke-virtual {v8, v9}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v8

    invoke-virtual {v8}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v8

    invoke-direct {p0, v1, v8}, Lnet/oauth/ConsumerProperties;->getURL(Ljava/net/URL;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v8

    new-instance v9, Ljava/lang/StringBuilder;

    invoke-direct {v9}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {v9, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v9

    const-string v10, ".serviceProvider.userAuthorizationURL"

    invoke-virtual {v9, v10}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v9

    invoke-virtual {v9}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v9

    invoke-direct {p0, v1, v9}, Lnet/oauth/ConsumerProperties;->getURL(Ljava/net/URL;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v9

    new-instance v10, Ljava/lang/StringBuilder;

    invoke-direct {v10}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {v10, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v10

    const-string v11, ".serviceProvider.accessTokenURL"

    invoke-virtual {v10, v11}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v10

    invoke-virtual {v10}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v10

    invoke-direct {p0, v1, v10}, Lnet/oauth/ConsumerProperties;->getURL(Ljava/net/URL;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v10

    invoke-direct {v7, v8, v9, v10}, Lnet/oauth/OAuthServiceProvider;-><init>(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V

    .line 104
    .local v7, serviceProvider:Lnet/oauth/OAuthServiceProvider;
    new-instance v3, Lnet/oauth/OAuthConsumer;

    iget-object v8, p0, Lnet/oauth/ConsumerProperties;->consumerProperties:Ljava/util/Properties;

    new-instance v9, Ljava/lang/StringBuilder;

    invoke-direct {v9}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {v9, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v9

    const-string v10, ".callbackURL"

    invoke-virtual {v9, v10}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v9

    invoke-virtual {v9}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v9

    invoke-virtual {v8, v9}, Ljava/util/Properties;->getProperty(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v8

    iget-object v9, p0, Lnet/oauth/ConsumerProperties;->consumerProperties:Ljava/util/Properties;

    new-instance v10, Ljava/lang/StringBuilder;

    invoke-direct {v10}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {v10, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v10

    const-string v11, ".consumerKey"

    invoke-virtual {v10, v11}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v10

    invoke-virtual {v10}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v10

    invoke-virtual {v9, v10}, Ljava/util/Properties;->getProperty(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v9

    iget-object v10, p0, Lnet/oauth/ConsumerProperties;->consumerProperties:Ljava/util/Properties;

    new-instance v11, Ljava/lang/StringBuilder;

    invoke-direct {v11}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {v11, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v11

    const-string v12, ".consumerSecret"

    invoke-virtual {v11, v12}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v11

    invoke-virtual {v11}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v11

    invoke-virtual {v10, v11}, Ljava/util/Properties;->getProperty(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v10

    invoke-direct {v3, v8, v9, v10, v7}, Lnet/oauth/OAuthConsumer;-><init>(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lnet/oauth/OAuthServiceProvider;)V

    .line 108
    .local v3, consumer:Lnet/oauth/OAuthConsumer;
    const-string v8, "name"

    invoke-virtual {v3, v8, p1}, Lnet/oauth/OAuthConsumer;->setProperty(Ljava/lang/String;Ljava/lang/Object;)V

    .line 109
    if-eqz v1, :cond_0

    .line 110
    const-string v8, "serviceProvider.baseURL"

    invoke-virtual {v3, v8, v1}, Lnet/oauth/OAuthConsumer;->setProperty(Ljava/lang/String;Ljava/lang/Object;)V

    .line 112
    :cond_0
    iget-object v8, p0, Lnet/oauth/ConsumerProperties;->consumerProperties:Ljava/util/Properties;

    invoke-virtual {v8}, Ljava/util/Properties;->entrySet()Ljava/util/Set;

    move-result-object v8

    invoke-interface {v8}, Ljava/util/Set;->iterator()Ljava/util/Iterator;

    move-result-object v4

    .local v4, i$:Ljava/util/Iterator;
    :cond_1
    :goto_1
    invoke-interface {v4}, Ljava/util/Iterator;->hasNext()Z

    move-result v8

    if-eqz v8, :cond_3

    invoke-interface {v4}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v5

    check-cast v5, Ljava/util/Map$Entry;

    .line 113
    .local v5, prop:Ljava/util/Map$Entry;
    invoke-interface {v5}, Ljava/util/Map$Entry;->getKey()Ljava/lang/Object;

    move-result-object v6

    check-cast v6, Ljava/lang/String;

    .line 114
    .local v6, propName:Ljava/lang/String;
    new-instance v8, Ljava/lang/StringBuilder;

    invoke-direct {v8}, Ljava/lang/StringBuilder;-><init>()V

    invoke-virtual {v8, p1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v8

    const-string v9, ".consumer."

    invoke-virtual {v8, v9}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v8

    invoke-virtual {v8}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v8

    invoke-virtual {v6, v8}, Ljava/lang/String;->startsWith(Ljava/lang/String;)Z

    move-result v8

    if-eqz v8, :cond_1

    .line 115
    invoke-virtual {p1}, Ljava/lang/String;->length()I

    move-result v8

    add-int/lit8 v8, v8, 0xa

    invoke-virtual {v6, v8}, Ljava/lang/String;->substring(I)Ljava/lang/String;

    move-result-object v2

    .line 116
    .local v2, c:Ljava/lang/String;
    invoke-interface {v5}, Ljava/util/Map$Entry;->getValue()Ljava/lang/Object;

    move-result-object v8

    invoke-virtual {v3, v2, v8}, Lnet/oauth/OAuthConsumer;->setProperty(Ljava/lang/String;Ljava/lang/Object;)V

    goto :goto_1

    .line 99
    .end local v1           #baseURL:Ljava/net/URL;
    .end local v2           #c:Ljava/lang/String;
    .end local v3           #consumer:Lnet/oauth/OAuthConsumer;
    .end local v4           #i$:Ljava/util/Iterator;
    .end local v5           #prop:Ljava/util/Map$Entry;
    .end local v6           #propName:Ljava/lang/String;
    .end local v7           #serviceProvider:Lnet/oauth/OAuthServiceProvider;
    :cond_2
    new-instance v1, Ljava/net/URL;

    invoke-direct {v1, v0}, Ljava/net/URL;-><init>(Ljava/lang/String;)V

    goto/16 :goto_0

    .line 119
    .restart local v1       #baseURL:Ljava/net/URL;
    .restart local v3       #consumer:Lnet/oauth/OAuthConsumer;
    .restart local v4       #i$:Ljava/util/Iterator;
    .restart local v7       #serviceProvider:Lnet/oauth/OAuthServiceProvider;
    :cond_3
    return-object v3
.end method
